
#pragma once

#include "glutVisualizer.h"

template <class T>
class Visualizer :public glutVisualizer<T>
{
	private:
		float radius;
	public:
		inline Visualizer(float radius)
		{ this->radius = radius; }
		virtual void onBegin()
		{
			glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
			glClear(GL_COLOR_BUFFER_BIT);
			glBegin(GL_TRIANGLES);
		}
		virtual void process(T data)
		{
			for (size_t i = 0; i < data.getSize(); i++)
			{
				vec3f pos = data.getPosition(i) / (2 * radius);
				static const float size = 0.01f;
				//Right-bottom.
				glColor3f(1.0f, 0.2f, 0.2f);
				glVertex3f(pos.x, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x + size, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x, pos.y + size, 0.0f);
				//Right-top.
				glColor3f(1.0f, 0.2f, 0.2f);
				glVertex3f(pos.x, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x + size, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x, pos.y - size, 0.0f);
				//Left-bottom.
				glColor3f(1.0f, 0.2f, 0.2f);
				glVertex3f(pos.x, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x - size, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x, pos.y + size, 0.0f);
				//Left-top.
				glColor3f(1.0f, 0.2f, 0.2f);
				glVertex3f(pos.x, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x - size, pos.y, 0.0f);
				glColor3f(0.25f, 0.05f, 0.05f);
				glVertex3f(pos.x, pos.y - size, 0.0f);
			}
		}
		virtual void onEnd()
		{
			glEnd();
			glutSwapBuffers();
		}
		inline Visualizer()
			:Node("Visualizer")
		{ /*nothing*/ }
};
